package cn.nio.test;

import lombok.SneakyThrows;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Main{
    static long start=System.currentTimeMillis();
    public static void main(String[] args) throws InterruptedException {
//        Thread.sleep(100);
        Main4 main4=new Main4();
        main4.f1();
        TimeUnit.SECONDS.sleep(2);
        long l = System.currentTimeMillis();
        Executors.newFixedThreadPool(1);
        Thread thread = new Thread() {
            private final long start = System.currentTimeMillis();

            @SneakyThrows
            @Override
            public void run() {
                Thread.sleep(100);
                long l = System.currentTimeMillis();
                System.out.println(l - start);
            }
        };
        thread.start();
        System.out.println(l-start);
        ExecutorService cachedThreadPool = Executors.newCachedThreadPool();
        cachedThreadPool.execute(Main::run);
        cachedThreadPool.execute(System.out::println);
    }

    private static void run() {
        System.out.println("线程名: " + Thread.currentThread().getName());
    }
}
